<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>AI数据分析结果</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: "Microsoft YaHei", Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            padding: 20px;
            min-height: 100vh;
        }
        
        .container {
            max-width: 1400px;
            margin: 0 auto;
        }
        
        .header {
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            margin-bottom: 20px;
            text-align: center;
        }
        
        .header h1 {
            color: #667eea;
            font-size: 32px;
            margin-bottom: 10px;
        }
        
        .stats {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 15px;
            margin-top: 20px;
        }
        
        .stat-card {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 20px;
            border-radius: 8px;
            text-align: center;
        }
        
        .stat-card .label {
            font-size: 14px;
            opacity: 0.9;
            margin-bottom: 10px;
        }
        
        .stat-card .value {
            font-size: 28px;
            font-weight: bold;
        }
        
        .chart-section {
            background: white;
            padding: 25px;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            margin-bottom: 20px;
        }
        
        .chart-section h2 {
            color: #333;
            margin-bottom: 20px;
            font-size: 24px;
            border-left: 4px solid #667eea;
            padding-left: 15px;
        }
        
        .chart-section img {
            width: 100%;
            height: auto;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        
        .grid-2 {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
            gap: 20px;
        }
        
        .model-table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 15px;
        }
        
        .model-table th,
        .model-table td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }
        
        .model-table th {
            background: #f5f5f5;
            font-weight: bold;
            color: #667eea;
        }
        
        .model-table tr:hover {
            background: #f9f9f9;
        }
        
        .best-model {
            background: #e8f5e9 !important;
            font-weight: bold;
        }
        
        @media (max-width: 768px) {
            .grid-2 {
                grid-template-columns: 1fr;
            }
            
            .header h1 {
                font-size: 24px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>🎬 豆瓣电影AI数据分析报告</h1>
            <div class="stats" id="stats">
                <!-- 统计信息将通过JavaScript动态填充 -->
            </div>
        </div>
        
        <div class="chart-section">
            <h2>📊 评分分布</h2>
            <img src="/uploads/ai-analysis/rating_distribution.png" alt="评分分布图" onerror="this.src=''">
        </div>
        
        <div class="grid-2">
            <div class="chart-section">
                <h2>📈 年份趋势</h2>
                <img src="/douban-analysis/年份与平均评分趋势.png" alt="年份趋势图" onerror="this.src=''">
            </div>
            
            <div class="chart-section">
                <h2>🔥 特征相关性</h2>
                <img src="/douban-analysis/年份与平均评分趋势.png" alt="相关性矩阵" onerror="this.src=''">
            </div>
        </div>
        
        <div class="grid-2">
            <div class="chart-section">
                <h2>📉 ROC曲线对比</h2>
                <img src="/uploads/ai-analysis/roc_curves.png" alt="ROC曲线" onerror="this.src=''">
            </div>
            
            <div class="chart-section">
                <h2>🎯 混淆矩阵</h2>
                <img src="/uploads/ai-analysis/roc_curves.png" alt="混淆矩阵" onerror="this.src=''">
            </div>
        </div>
        
        <div class="chart-section">
            <h2>🏆 模型性能对比</h2>
            <table class="model-table" id="model-table">
                <thead>
                    <tr>
                        <th>模型</th>
                        <th>准确率</th>
                        <th>F1分数</th>
                        <th>ROC-AUC</th>
                        <th>TN</th>
                        <th>FP</th>
                        <th>FN</th>
                        <th>TP</th>
                    </tr>
                </thead>
                <tbody>
                    <!-- 模型数据将通过JavaScript动态填充 -->
                </tbody>
            </table>
        </div>
    </div>
    
    <script>
        // 从API获取数据
        async function loadAnalysisData() {
            try {
                const response = await fetch('/api/admin/analysis/ai-analysis', {
                    method: 'POST'
                });
                const result = await response.json();
                
                if (result.code !== 1) {
                    throw new Error(result.message || '获取数据失败');
                }
                
                const data = result.response;
                
                // 填充统计信息
                if (data.movieStats) {
                    const statsHtml = `
                        <div class="stat-card">
                            <div class="label">总电影数</div>
                            <div class="value">${data.movieStats.totalCount}</div>
                        </div>
                        <div class="stat-card">
                            <div class="label">平均评分</div>
                            <div class="value">${data.movieStats.avgRating}</div>
                        </div>
                        <div class="stat-card">
                            <div class="label">高分电影</div>
                            <div class="value">${data.movieStats.highRatingCount}</div>
                        </div>
                        <div class="stat-card">
                            <div class="label">最佳模型</div>
                            <div class="value" style="font-size:18px">${data.modelResults?.bestModel || 'N/A'}</div>
                        </div>
                    `;
                    document.getElementById('stats').innerHTML = statsHtml;
                }
                
                // 填充模型表格
                if (data.modelResults && data.modelResults.results) {
                    const bestModel = data.modelResults.bestModel;
                    const tbody = document.getElementById('model-table').querySelector('tbody');
                    const rows = data.modelResults.results.map(model => `
                        <tr class="${model.model === bestModel ? 'best-model' : ''}">
                            <td>${model.model}${model.model === bestModel ? ' 🥇' : ''}</td>
                            <td>${model.accuracy}</td>
                            <td>${model.f1}</td>
                            <td>${model.rocAuc}</td>
                            <td>${model.tn}</td>
                            <td>${model.fp}</td>
                            <td>${model.fn}</td>
                            <td>${model.tp}</td>
                        </tr>
                    `).join('');
                    tbody.innerHTML = rows;
                }
            } catch (error) {
                console.error('加载分析数据失败:', error);
                document.getElementById('stats').innerHTML = '<div class="stat-card"><div class="label">数据加载失败</div></div>';
            }
        }
        
        // 页面加载时获取数据
        window.addEventListener('DOMContentLoaded', loadAnalysisData);
    </script>
</body>
</html>
